package com.lingyun.common.utils;

/**
 * Created by bai on 2017/1/15.
 */
public class LatLngDistanceUtil {
    private static final double PI = 3.14159265358979323; //圆周率
    private static final double EARTH_R = 6371229;              //地球的半径


    public static double getDistance(double longt1, double lat1, double longt2, double lat2){
        double x,y,distance;
        x=(longt2-longt1)*PI* EARTH_R *Math.cos( ((lat1+lat2)/2) *PI/180)/180;
        y=(lat2-lat1)*PI* EARTH_R /180;
        distance=Math.hypot(x,y);
        return distance;
    }

    public static double getLongt(double longt1, double lat1, double distance){
        double a = (180*distance)/(PI* EARTH_R *Math.cos(lat1*PI/180));
        return a;
    }


    public static double getLat(double longt1, double lat1, double distance){
        double a = (180*distance)/(PI* EARTH_R *Math.cos(lat1*PI/180));
        return a;
    }

    public static void main(String[] args){

        double longt = LatLngDistanceUtil.getLongt(112.0235, 23.2563, 10227.5985);
        System.out.println(longt);

        double lat = LatLngDistanceUtil.getLat(112.0235, 23.2563, 11131.9859);
        System.out.println(lat);

    }
}
